package ar.edu.uba.fi.jmit.graphvisualizer.server.service;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.graphvisualizer.server.ResourceProperties;
import ar.edu.uba.fi.jmit.graphvisualizer.server.storage.Pair;
import ar.edu.uba.fi.jmit.graphvisualizer.server.storage.Registry;
import ar.edu.uba.fi.jmit.graphvisualizer.shared.TimeValue;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public abstract class AbstractServiceImpl extends RemoteServiceServlet {
	
	private static final long serialVersionUID = 6120706417526686537L;
	protected Logger logger = Logger.getLogger(this.getClass());
	
	protected List<TimeValue> generateTimeValueListForProperty(String application, String monitorName, String mapProperty) {
		List<Pair<Map<String, Serializable>>> pairList = Registry.getMonitoringDataStorage().getData(application, monitorName);
		List<TimeValue> timeValueList = new LinkedList<TimeValue>();
		if(pairList != null) {
			logger.debug(this.getClass() + " found " + pairList.size() + " pairs.");
			for(Pair<Map<String, Serializable>> pair:pairList) {
				timeValueList.add(new TimeValue(pair.getDate(), pair.getValue().get(ResourceProperties.getProperty(mapProperty))));
			}
		}else {
			logger.debug("No information found for application " + application + " and monitor " + monitorName + ".");
		}
		return timeValueList;
	}

}
